<template>
  <div class="sys-section-bg">
    <div style="height:32px;"></div>
    <div class="page-title">
      <el-icon><i-ep-setting /></el-icon>
      <span style="margin-left: 8px; font-size: 20px; font-weight: bold;">系统设置</span>
    </div>
    <el-form :model="sysSettingsEditForm" :rules="sysSettingsRules" ref="sysSettingsFormRef" label-width="120px" style="width: 600px;">
      <el-form-item label="系统名称" prop="name">
        <el-input v-model="sysSettingsEditForm.name" :disabled="!sysSettingsEditMode" />
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input v-model="sysSettingsEditForm.version" :disabled="!sysSettingsEditMode" />
      </el-form-item>
      <el-form-item label="系统语言" prop="language">
        <el-select v-model="sysSettingsEditForm.language" placeholder="请选择语言" :disabled="!sysSettingsEditMode">
          <el-option label="简体中文" value="zh-CN" />
          <el-option label="English" value="en-US" />
        </el-select>
      </el-form-item>
      <el-form-item label="时区设置" prop="timezone">
        <el-select v-model="sysSettingsEditForm.timezone" placeholder="请选择时区" :disabled="!sysSettingsEditMode">
          <el-option label="中国标准时间 (GMT+8)" value="Asia/Shanghai" />
          <el-option label="美国东部时间 (GMT-5)" value="America/New_York" />
          <el-option label="UTC" value="UTC" />
        </el-select>
      </el-form-item>
      <el-form-item label="管理员邮箱" prop="adminEmail">
        <el-input v-model="sysSettingsEditForm.adminEmail" :disabled="!sysSettingsEditMode" />
      </el-form-item>
      <el-form-item>
        <el-button v-if="!sysSettingsEditMode" type="primary" @click="startSysSettingsEdit">编辑</el-button>
        <template v-else>
          <el-button type="primary" @click="submitSysSettings">保存</el-button>
          <el-button @click="cancelSysSettingsEdit" style="margin-left: 8px;">取消</el-button>
        </template>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

// 系统设置数据
const sysSettingsEditForm = reactive({
  name: '通用后台管理系统',
  version: '1.0.0',
  language: 'zh-CN',
  timezone: 'Asia/Shanghai',
  adminEmail: 'admin@test.com'
})

const sysSettingsEditMode = ref(false)
const sysSettingsFormRef = ref(null)
const sysSettingsRules = {
  name: [{ required: true, message: '请输入系统名称', trigger: 'blur' }],
  version: [{ required: true, message: '请输入版本号', trigger: 'blur' }],
  language: [{ required: true, message: '请选择系统语言', trigger: 'change' }],
  timezone: [{ required: true, message: '请选择时区', trigger: 'change' }],
  adminEmail: [
    { required: true, message: '请输入管理员邮箱', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' }
  ]
}

function startSysSettingsEdit() {
  sysSettingsEditMode.value = true
}

function cancelSysSettingsEdit() {
  sysSettingsEditMode.value = false
  // 重置表单数据
  Object.assign(sysSettingsEditForm, {
    name: '通用后台管理系统',
    version: '1.0.0',
    language: 'zh-CN',
    timezone: 'Asia/Shanghai',
    adminEmail: 'admin@test.com'
  })
}

function submitSysSettings() {
  sysSettingsFormRef.value.validate(valid => {
    if (!valid) return
    
    // 这里可以添加保存到后端的逻辑
    ElMessage.success('系统设置已保存')
    sysSettingsEditMode.value = false
  })
}

// 组件挂载时获取数据
onMounted(() => {
  // 这里可以添加从后端获取系统设置数据的逻辑
  console.log('系统设置组件已加载')
})
</script>

<style scoped>
.sys-section-bg {
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.page-title {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  color: #333;
}
</style> 